package com.apache.funds.util;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.apache.tools.DateUtils;
import com.apache.tools.DateUtils.FmtStr;

public class Constants {

	// 方向的常量
	public final static class Description {
		public final static String IN = "in";
		public final static String OUT = "out";
	}

	// 交易类型
	public final static class TradeType {
		//		public final static String PUB_SELL_ORDER = "PSOD"; //挂卖单**
		//		public final static String RESPONSE_BUY_ORDER = "RBOD"; // 应买单***
		//		public final static String RESPONSE_SELL_ORDER = "RSOD"; // 应卖单***
		//		public final static String CANCEL_SELL_ORDER = "CSOD"; // 撤买单**

		public final static String PUB_BUY_ORDER = "PBOD"; // 冻结[m1→m2]
		public final static String CANCEL_BUY_ORDER = "CBOD"; // 解冻[m2→m1]
		public final static String ADD_PRODUCT = "APRD";
		public final static String FUNDS_DELIVERY = "DELV";//资金交割

		public final static String FUNDS_INTO = "FINT"; //入金、充值[m1 in]
		public final static String FUNDS_OUTTO = "FOUT";//出金、提现[m1 out]
		public final static String THE_BANK_DELIVERY = "TBDV";//交割,买方[m2,out] -> 卖方[m1,in][m3,in]

		public final static String OTHER_BANK_DELIVERY = "OBDV"; // 他行已收 买方[m5,out]-> 卖方[m1,in][m4,in]
		public final static String OTHER_BANK_DELIVERY_FUREN_TO_YIFU = "OBFY"; // 他行已付[m2→m5]

		public final static String UNLOCK_TN = "UNLK"; //TN解锁 [m3,out]
		public final static String OTHER_BANLANCE = "OBBN"; //他行结算[m4→m3]

		public final static String THE_BANK_FEE_BUEY_MOVE = "TFBM"; //买方手续费移动[m2,out][m6,in]
		public final static String THE_BANK_FEE_SELL_MOVE = "TFSM"; // 本行卖方手续费移动[m1,out][m6,in]
		public final static String OTHER_BANK_FEE_SELL_MOVE = "OFSM"; // 他行卖方手续费移动[m1,out][m6,in]
		public final static String FEE_DELIVERY = "FEDV"; // 手续费交割,付款方[m6,out] → 交易所平台[m1,in]
		public final static String AFTER_PAYMENT = "APFE"; //补交手续费移动,付款方[m1,out][m6,in]

		public final static String DELIVERY_FBDV = "FBDV";//交割给平台（一级市场发售申购交割给交易所账户）,买方[m2,out]，交易所平台[m1,in]
		public final static String DELIVERY_FADV = "FADV";//交割给平台(买方有效→交易所)，买方[m1,out]，交易所平台[m1,in]

	}

	// 委托类型
	public final static class OrderType {
		public final static String BUY = "B"; //买单
		public final static String SELL = "S"; //卖单
	}

	// 状态
	public final static class STATUS {
		public final static String EFFECTIVE = "1"; //有效
		public final static String INEFFECTIVE = "0"; //无效
	}

	//	public String checkStorageType(String tradeType) {
	//		if (TradeType.PUB_BUY_ORDER.equals(tradeType)) {
	//			return "";
	//		} else if (TradeType.PUB_SELL_ORDER.equals(tradeType)) {
	//			return "c1";
	//		} else if (TradeType.RESPONSE_BUY_ORDER.equals(tradeType)) {
	//			return "";
	//		} else if (TradeType.RESPONSE_SELL_ORDER.equals(tradeType)) {
	//			return "";
	//		} else if (TradeType.CANCEL_BUY_ORDER.equals(tradeType)) {
	//			return "";
	//		} else if (TradeType.CANCEL_SELL_ORDER.equals(tradeType)) {
	//			return "";
	//		} else if (TradeType.ADD_PRODUCT.equals(tradeType)) {
	//			return "";
	//		} else {
	//			return "";
	//		}
	//	}

	public final static class Msg {
		public final static String F000 = "F000:操作成功";
		public final static String F001 = "F001:操作失败";
		public final static String F002 = "F002:通信失败";
		public final static String F003 = "F003:资金账号不能为空";
		public final static String F004 = "F004:资金账户不存在";
		public final static String F005 = "F005:可操作金额不足";
		public final static String F006 = "F006:参数不能为空";
		public final static String F007 = "F007:参数格式不对";
		public final static String F008 = "F008:规则校验失败";
		public final static String F009 = "F009:规则校验成功";
		public final static String F010 = "F010:未查询到您的余额账户";//可能是前一日日终余额，未汇总导致的
		public final static String F011 = "F011:账户或口令校验失败";
		public final static String F012 = "F012:账户口令不对";
	}

	public static long timeToDate(long time) {
		String dateTime = DateUtils.longToStr(time, FmtStr.yyyyMMdd);
		long dateTrade = 0l;
		try {
			dateTrade = DateUtils.toLong(DateUtils.parse(dateTime));
		} catch (ParseException e) {
			e.printStackTrace();
			dateTrade = time;
		}
		return dateTrade;
	}

	/**
	 * 模拟模板，目前先用此方式模拟，将来可以从数据库中通过交易类型获取
	 * @param tradeType 交易类型
	 * @return
	 */
	public static Map<String, List<FundsTemplate>> getStorageTemplate(String tradeType) {
		Map<String, List<FundsTemplate>> map = new HashMap<String, List<FundsTemplate>>();
		// 将来从数据库中获取时，tradeType将作为参数查询
		//冻结
		if (TradeType.PUB_BUY_ORDER.equals(tradeType)) {
			List<FundsTemplate> list = new ArrayList<FundsTemplate>();
			FundsTemplate sv = new FundsTemplate();
			sv.setTradeType(TradeType.PUB_BUY_ORDER);
			sv.setCaption("m1");
			sv.setDirection("out");
			list.add(sv);
			FundsTemplate sv1 = new FundsTemplate();
			sv1.setTradeType(TradeType.PUB_BUY_ORDER);
			sv1.setCaption("m2");
			sv1.setDirection("in");
			list.add(sv1);
			map.put(TradeType.PUB_BUY_ORDER, list);
			//资金交割
		} else if (TradeType.FUNDS_DELIVERY.equals(tradeType)) {
			List<FundsTemplate> list = new ArrayList<FundsTemplate>();
			FundsTemplate sv = new FundsTemplate();
			sv.setTradeType(TradeType.FUNDS_DELIVERY);
			sv.setCaption("m2");
			sv.setDirection("out");
			list.add(sv);
			FundsTemplate sv1 = new FundsTemplate();
			sv1.setTradeType(TradeType.FUNDS_DELIVERY);
			sv1.setCaption("m1");
			sv1.setDirection("in");
			list.add(sv1);
			map.put(TradeType.FUNDS_DELIVERY, list);
		} else if (TradeType.CANCEL_BUY_ORDER.equals(tradeType)) { // 解冻
			List<FundsTemplate> list2 = new ArrayList<FundsTemplate>();
			FundsTemplate sv2 = new FundsTemplate();
			sv2.setTradeType(TradeType.CANCEL_BUY_ORDER);
			sv2.setCaption("m1");
			sv2.setDirection("in");
			list2.add(sv2);
			FundsTemplate sv3 = new FundsTemplate();
			sv3.setTradeType(TradeType.CANCEL_BUY_ORDER);
			sv3.setCaption("m2");
			sv3.setDirection("out");
			list2.add(sv3);
			map.put(TradeType.CANCEL_BUY_ORDER, list2);
		} else if (TradeType.FUNDS_INTO.equals(tradeType)) { // 入金
			List<FundsTemplate> listFi = new ArrayList<FundsTemplate>();
			FundsTemplate FI = new FundsTemplate();
			FI.setTradeType(TradeType.FUNDS_INTO);
			FI.setCaption("m1");
			FI.setDirection("in");
			listFi.add(FI);
			map.put(TradeType.FUNDS_INTO, listFi);
		} else if (TradeType.FUNDS_OUTTO.equals(tradeType)) { //出金
			List<FundsTemplate> listFO = new ArrayList<FundsTemplate>();
			FundsTemplate fo = new FundsTemplate();
			fo.setTradeType(TradeType.FUNDS_OUTTO);
			fo.setCaption("m1");
			fo.setDirection("out");
			listFO.add(fo);
			map.put(TradeType.FUNDS_OUTTO, listFO);
		} else if (TradeType.THE_BANK_DELIVERY.equals(tradeType)) { //本行资金交割
			List<FundsTemplate> listTB = new ArrayList<FundsTemplate>();
			FundsTemplate sv2 = new FundsTemplate();
			sv2.setTradeType(TradeType.THE_BANK_DELIVERY);
			sv2.setCaption("m2");
			sv2.setDirection("out");
			listTB.add(sv2);
			FundsTemplate sv3 = new FundsTemplate();
			sv3.setTradeType(TradeType.THE_BANK_DELIVERY);
			sv3.setCaption("m3"); // TN
			sv3.setDirection("in");
			listTB.add(sv3);
			FundsTemplate sv4 = new FundsTemplate();
			sv4.setTradeType(TradeType.THE_BANK_DELIVERY);
			sv4.setCaption("m1"); // TN
			sv4.setDirection("in");
			listTB.add(sv4);
			map.put(TradeType.THE_BANK_DELIVERY, listTB);
		} else if (TradeType.OTHER_BANK_DELIVERY.equals(tradeType)) { // 他行资金交割
			List<FundsTemplate> list2 = new ArrayList<FundsTemplate>();
			FundsTemplate sv2 = new FundsTemplate();
			sv2.setTradeType(TradeType.OTHER_BANK_DELIVERY);
			sv2.setCaption("m5");
			sv2.setDirection("out");
			list2.add(sv2);
			FundsTemplate sv3 = new FundsTemplate();
			sv3.setTradeType(TradeType.OTHER_BANK_DELIVERY);
			sv3.setCaption("m4"); //他行已收
			sv3.setDirection("in");
			list2.add(sv3);
			FundsTemplate sv4 = new FundsTemplate();
			sv4.setTradeType(TradeType.OTHER_BANK_DELIVERY);
			sv4.setCaption("m1"); //
			sv4.setDirection("in");
			list2.add(sv4);
			map.put(TradeType.OTHER_BANK_DELIVERY, list2);
		} else if (TradeType.OTHER_BANK_DELIVERY_FUREN_TO_YIFU.equals(tradeType)) { // 冻结移动到已付
			List<FundsTemplate> list2 = new ArrayList<FundsTemplate>();
			FundsTemplate sv2 = new FundsTemplate();
			sv2.setTradeType(TradeType.OTHER_BANK_DELIVERY_FUREN_TO_YIFU);
			sv2.setCaption("m2");
			sv2.setDirection("out");
			list2.add(sv2);
			FundsTemplate sv3 = new FundsTemplate();
			sv3.setTradeType(TradeType.OTHER_BANK_DELIVERY_FUREN_TO_YIFU);
			sv3.setCaption("m5"); //他行已收
			sv3.setDirection("in");
			list2.add(sv3);
			map.put(TradeType.OTHER_BANK_DELIVERY_FUREN_TO_YIFU, list2);
		} else if (TradeType.UNLOCK_TN.equals(tradeType)) { // TN解锁
			List<FundsTemplate> list2 = new ArrayList<FundsTemplate>();
			FundsTemplate sv2 = new FundsTemplate();
			sv2.setTradeType(TradeType.UNLOCK_TN);
			sv2.setCaption("m3");
			sv2.setDirection("out");
			list2.add(sv2);
			map.put(TradeType.UNLOCK_TN, list2);
		} else if (TradeType.OTHER_BANLANCE.equals(tradeType)) { // 他行结算
			List<FundsTemplate> list2 = new ArrayList<FundsTemplate>();
			FundsTemplate sv2 = new FundsTemplate();
			sv2.setTradeType(TradeType.OTHER_BANLANCE);
			sv2.setCaption("m4"); // 他行已收
			sv2.setDirection("out");
			list2.add(sv2);
			FundsTemplate sv3 = new FundsTemplate();
			sv3.setTradeType(TradeType.OTHER_BANLANCE);
			sv3.setCaption("m3");
			sv3.setDirection("in");
			list2.add(sv3);
			map.put(TradeType.OTHER_BANLANCE, list2);
		} else if (TradeType.THE_BANK_FEE_BUEY_MOVE.equals(tradeType)) { // 买方手续费移动
			List<FundsTemplate> list2 = new ArrayList<FundsTemplate>();
			FundsTemplate sv2 = new FundsTemplate();
			sv2.setTradeType(TradeType.THE_BANK_FEE_BUEY_MOVE);
			sv2.setCaption("m2");
			sv2.setDirection("out");
			list2.add(sv2);
			FundsTemplate sv3 = new FundsTemplate();
			sv3.setTradeType(TradeType.THE_BANK_FEE_BUEY_MOVE);
			sv3.setCaption("m6");
			sv3.setDirection("in");
			list2.add(sv3);
			map.put(TradeType.THE_BANK_FEE_BUEY_MOVE, list2);
		} else if (TradeType.THE_BANK_FEE_SELL_MOVE.equals(tradeType)) { // 
			List<FundsTemplate> list2 = new ArrayList<FundsTemplate>();
			FundsTemplate sv3 = new FundsTemplate();
			sv3.setTradeType(TradeType.THE_BANK_FEE_SELL_MOVE);
			sv3.setCaption("m6");
			sv3.setDirection("in");
			list2.add(sv3);
			FundsTemplate sv4 = new FundsTemplate();
			sv4.setTradeType(TradeType.THE_BANK_FEE_SELL_MOVE);
			sv4.setCaption("m1");
			sv4.setDirection("out");
			list2.add(sv4);
			map.put(TradeType.THE_BANK_FEE_SELL_MOVE, list2);
		} else if (TradeType.OTHER_BANK_FEE_SELL_MOVE.equals(tradeType)) { // 
			List<FundsTemplate> list2 = new ArrayList<FundsTemplate>();
			FundsTemplate sv3 = new FundsTemplate();
			sv3.setTradeType(TradeType.OTHER_BANK_FEE_SELL_MOVE);
			sv3.setCaption("m6");
			sv3.setDirection("in");
			list2.add(sv3);
			FundsTemplate sv4 = new FundsTemplate();
			sv4.setTradeType(TradeType.OTHER_BANK_FEE_SELL_MOVE);
			sv4.setCaption("m1");
			sv4.setDirection("out");
			list2.add(sv4);
			map.put(TradeType.OTHER_BANK_FEE_SELL_MOVE, list2);
		} else if (TradeType.FEE_DELIVERY.equals(tradeType)) { // 
			List<FundsTemplate> list2 = new ArrayList<FundsTemplate>();
			FundsTemplate sv2 = new FundsTemplate();
			sv2.setTradeType(TradeType.FEE_DELIVERY);
			sv2.setCaption("m6");
			sv2.setDirection("out");
			list2.add(sv2);
			FundsTemplate sv3 = new FundsTemplate();
			sv3.setTradeType(TradeType.FEE_DELIVERY);
			sv3.setCaption("m1");
			sv3.setDirection("in");
			list2.add(sv3);
			map.put(TradeType.FEE_DELIVERY, list2);
		} else if (TradeType.AFTER_PAYMENT.equals(tradeType)) { // 
			List<FundsTemplate> list2 = new ArrayList<FundsTemplate>();
			FundsTemplate sv2 = new FundsTemplate();
			sv2.setTradeType(TradeType.AFTER_PAYMENT);
			sv2.setCaption("m1");
			sv2.setDirection("out");
			list2.add(sv2);
			FundsTemplate sv3 = new FundsTemplate();
			sv3.setTradeType(TradeType.AFTER_PAYMENT);
			sv3.setCaption("m6");
			sv3.setDirection("in");
			list2.add(sv3);
			map.put(TradeType.AFTER_PAYMENT, list2);
		} else if (TradeType.DELIVERY_FBDV.equals(tradeType)) { // 
			List<FundsTemplate> list2 = new ArrayList<FundsTemplate>();
			FundsTemplate sv2 = new FundsTemplate();
			sv2.setTradeType(TradeType.DELIVERY_FBDV);
			sv2.setCaption("m2");
			sv2.setDirection("out");
			list2.add(sv2);
			FundsTemplate sv3 = new FundsTemplate();
			sv3.setTradeType(TradeType.DELIVERY_FBDV);
			sv3.setCaption("m1");
			sv3.setDirection("in");
			list2.add(sv3);
			map.put(TradeType.DELIVERY_FBDV, list2);
		} else if (TradeType.DELIVERY_FADV.equals(tradeType)) { // 
			List<FundsTemplate> list2 = new ArrayList<FundsTemplate>();
			FundsTemplate sv2 = new FundsTemplate();
			sv2.setTradeType(TradeType.DELIVERY_FADV);
			sv2.setCaption("m1");
			sv2.setDirection("out");
			list2.add(sv2);
			FundsTemplate sv3 = new FundsTemplate();
			sv3.setTradeType(TradeType.DELIVERY_FADV);
			sv3.setCaption("m1");
			sv3.setDirection("in");
			list2.add(sv3);
			map.put(TradeType.DELIVERY_FADV, list2);
		}
		return map;

	}

	/**
	 * 获取所有科目
	 * @return
	 */
	public static List<FundsTemplate> getAllCaptionTemplate() {
		List<FundsTemplate> list = new ArrayList<FundsTemplate>();
		FundsTemplate sv = new FundsTemplate();
		sv.setCaption("m1");
		list.add(sv);
		FundsTemplate sv1 = new FundsTemplate();
		sv1.setCaption("m2");
		list.add(sv1);
		FundsTemplate sv2 = new FundsTemplate();
		sv2.setCaption("m3");
		list.add(sv2);
		FundsTemplate sv3 = new FundsTemplate();
		sv3.setCaption("m4");
		list.add(sv3);
		FundsTemplate sv4 = new FundsTemplate();
		sv4.setCaption("m5");
		list.add(sv4);
		FundsTemplate sv5 = new FundsTemplate();
		sv5.setCaption("m6");
		list.add(sv5);
		return list;
	}

	public static void main(String[] args) {
		System.out.println(DateUtils.getDate().getTime());
		System.out.println(DateUtils.format(DateUtils.getDate(), DateUtils.FmtStr.yyyyMMdd_HHmmssSSS.toString()));
	}
}
